package m202405.d28;

import java.util.Stack;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/28 16:58
 */
public class Q739 {
    public int[] dailyTemperatures(int[] temperatures) {
        Stack<int[]> stack = new Stack<>();

        int[] res = new int[temperatures.length];

        for (int i = 0; i < temperatures.length; i++) {
            if (!stack.isEmpty()) {
                while ( !stack.isEmpty() && stack.peek()[1] < temperatures[i]) {
                    int[] pop = stack.pop();
                    res[pop[0]] = i - pop[0];
                }
            }
            stack.push(new int[]{i, temperatures[i]});
        }
        return res;
    }
}
